<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta name="referrer" content="strict-origin-when-cross-origin" />
		<title>人机验证</title>
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
		<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" async defer></script>
		<script>
			window.onloadTurnstileCallback = function () {
				turnstile.render("#cfts", {
					sitekey: "0x4AAAAAAAOzWQkEw2f6U-bV",
					callback: function (token) {
						console.log(`Challenge Success ${token}`);
						$.ajax({
							url: "/verify/",
							type: "POST",
							dataType: "json",
							data: {
								verify_token: token
							},
							success: function (response) {
								if ("err" in response && response["err"] != "") {
									alert(response["err"]);
									turnstile.reset("#cfts");
									return;
								}
								window.close();
							},
							error: function (xhr, status, error) {
								console.error("Ajax请求失败：", error);
								turnstile.reset("#cfts");
							}
						});
					}
				});
			};
		</script>
	</head>
	<body>
		<h2>Verifying</h2>
		<div id="cfts"></div>
	</body>
</html>
